//
//  LFNewFutureViewController.swift
//  SDAutoWeibo
//
//  Created by 刘健 on 16/3/23.
//  Copyright © 2016年 Clemmie. All rights reserved.
//

import UIKit

class LFNewFeatureViewController: UICollectionViewController,LFNewFeatureViewCellDelegate {
    
    let layout = UICollectionViewFlowLayout()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //
        //        collectionView = UICollectionView(frame: UIScreen.mainScreen().bounds, collectionViewLayout: layout)
        
        collectionView?.registerClass(LFNewFeatureViewCell.self, forCellWithReuseIdentifier: "cell")
        
    }
    
    init() {
        super.init(collectionViewLayout: layout)
        
        setupLayout()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置collection属性
    func setupLayout() {
        
        collectionView?.backgroundColor = UIColor.whiteColor()
        
        layout.itemSize = UIScreen.mainScreen().bounds.size
        
        layout.minimumLineSpacing = 0
        
        layout.scrollDirection = UICollectionViewScrollDirection.Horizontal
        
        collectionView?.bounces = false
        
        collectionView?.pagingEnabled = true
    }
    
    
    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 4;
    }
    
    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell = collectionView .dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! LFNewFeatureViewCell
        
        cell.index = indexPath.item
        
        cell.delegate = self;
        
        return cell
        
    }
    
    override func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
        let offsetIndex = Int(scrollView.contentOffset.x / UIScreen.mainScreen().bounds.width)
        
        if offsetIndex == LFPageCounts - 1 {
            
            let indexPath = NSIndexPath(forItem: offsetIndex, inSection: 0)
            let cell = collectionView?.cellForItemAtIndexPath(indexPath) as! LFNewFeatureViewCell
            
            cell.startBtnAnimation()
        }
        
    }
    
      //MARK : -- 点击startBtn 跳转
    func didClickStartBtn() {
        AppDelegate.JumpViewController(LFMainViewController())
    }
   
}



